<?php
namespace App\Admin\Controllers;
use App\Http\Controllers\Controller;
use App\Model\Gift;
use App\Model\SettingAllocate;
use App\Model\UserProfile;
use App\Util\AliyunUtil;
use App\Util\ComUtil;
use Encore\Admin\Controllers\ModelForm;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;
use App\Model\Tape;
class TapeController extends Controller
{
    use ModelForm;

    public function index()
    {
        $content = new Content();
        $content->header('电话录音上传列表');
        $content->body($this->grid());
        return $content;
    }

    protected function grid()
    {
        $grid = new Grid(new Tape());
        $grid->model();
        $grid->user_id('用户内部ID')->sortable()->editable();
        $grid->userProfile()->user_profile_id('用户ID');
        $grid->userProfile()->nick_name('用户昵称');
        $grid->tape_url('语音列表')->display(function ($data) {
            $url =  AliyunUtil::IMG_HOST_V2.$data;
            return ComUtil::buildAudio($url, 'audio');
        });
        $grid->filter(function ($filter) {
            $filter->expand();
            $filter->disableIdFilter();
            $filter->column(1 / 2, function ($filter) {
                $filter->equal('user_id', '用户ID');

            });

        });


        //禁用导出
        $grid->disableExport();
        //禁用行选择
        $grid->disableRowSelector();
        $grid->actions(function (Grid\Displayers\Actions $actions) {
            $actions->disableDelete();
            $actions->disableView();
        });
        return $grid;
    }

    public function create()
    {
        $content = new Content();
        $content->header('创建');
        $content->body($this->form());
        return $content;
    }

    protected function form()
    {
        $form = new Form(new Tape());

        $form->text('user_id', '用户内部ID')->default(1)->required();
        $form->file('tape_url', '语音')->uniqueName();
        return $form;
    }


}
